from django.db.models import QuerySet

from server.apps.main.logic.posts.validation import ValidTaskData
from server.apps.main.models import Todo


def create(valid_data: ValidTaskData) -> Todo:
    """
    Creates a new blog post.

    Note: you cannot create a BlogPost from **invalid** data!
    mypy will catch that.
    """
    return Todo.objects.create(
        title=valid_data.title,
        description=valid_data.description,
        is_done=valid_data.is_done,
    )

def del_task(task_id: int) -> None:
    Todo.objects.filter(id=task_id).delete()
    return 

def done_task(task_id: int) -> int:
    Todo.objects.filter(id=task_id).update(is_done=True)
    return 

def edit(task_id: int, valid_data: ValidTaskData) -> int:
    return Todo.objects.filter(id=task_id).update(
        title=valid_data.title,
        description=valid_data.description,
        is_done=valid_data.is_done,
    )